/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.drone.configuration;

import java.util.Map;
import java.util.TreeMap;

public class Configurations
{
	private Map<String,String> configurations;

	public Configurations()
	{
		this.configurations = new TreeMap<String, String>();
	}

	public Configurations(Configurations c)
	{
		this.configurations = new TreeMap<String, String>(c.configurations);
	}

	public void put(String key, String value)
	{
		this.configurations.put(key, value);
	}
	
	public void remove(String key)
	{
		this.configurations.remove(key);
	}

	public String value(String key)
	{
		return this.configurations.get(key);
	}
	
	public static String[] parseAConfigLine(String line) 
	{
		String[] res = line.split("=");
		if (res.length == 2)
		{
			res[0].trim();
			res[1].trim();
			return res;
		}
		return null;
	}
	public Map<String,String> getConfigurations()
	{
		return this.configurations;
	}
	
	public String toString()
	{
		StringBuilder tmp = new StringBuilder();
		for(Map.Entry<String, String> c: this.configurations.entrySet())
		{
			tmp.append(c.getKey()).append("=").append(c.getValue().toLowerCase()).append('\n');
		}
		return tmp.toString();
	}
}
